home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Text and Fonts / Antialiasing with Text / GDITEST50.dpr
Encoding:
Text File  |  2003-10-15  |  2.7 KB  |  100 lines

  1. program GDITEST50;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   FontFamily: TGPFontFamily;
  14.   Font: TGPFont;
  15.   SolidBrush: TGPSolidBrush;
  16. begin
  17.   graphics   := TGPGraphics.Create(DC);
  18.   FontFamily := TGPFontFamily.Create('Times New Roman');
  19.   Font       := TGPFont.Create(FontFamily, 32, FontStyleRegular, UnitPixel);
  20.   SolidBrush := TGPSolidBrush.Create(MakeColor(255, 0, 0, 255));
  21.  
  22.   graphics.SetTextRenderingHint(TextRenderingHintSingleBitPerPixel);
  23.   graphics.DrawString('SingleBitPerPixel', -1, font, MakePoint(10.0, 10.0), solidBrush);
  24.  
  25.   graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
  26.   graphics.DrawString('AntiAlias', -1, font, MakePoint(10.0, 60.0), solidBrush);
  27.  
  28.   graphics.Free;
  29.   FontFamily.Free;
  30.   Font.Free;
  31.   SolidBrush.Free;
  32. end;
  33.  
  34.  
  35. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  36. var
  37.   Handle: HDC;
  38.   ps: PAINTSTRUCT;
  39. begin
  40.   case message of
  41.     WM_PAINT:
  42.       begin
  43.         Handle := BeginPaint(Wnd, ps);
  44.         OnPaint(Handle);
  45.         EndPaint(Wnd, ps);
  46.         result := 0;
  47.       end;
  48.  
  49.     WM_DESTROY:
  50.       begin
  51.         PostQuitMessage(0);
  52.         result := 0;
  53.       end;
  54.  
  55.    else
  56.       result := DefWindowProc(Wnd, message, wParam, lParam);
  57.    end;
  58. end;
  59.  
  60. var
  61.   hWnd     : THandle;
  62.   Msg      : TMsg;
  63.   wndClass : TWndClass;
  64. begin
  65.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  66.    wndClass.lpfnWndProc    := @WndProc;
  67.    wndClass.cbClsExtra     := 0;
  68.    wndClass.cbWndExtra     := 0;
  69.    wndClass.hInstance      := hInstance;
  70.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  71.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  72.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  73.    wndClass.lpszMenuName   := nil;
  74.    wndClass.lpszClassName  := 'GettingStarted';
  75.  
  76.    RegisterClass(wndClass);
  77.  
  78.    hWnd := CreateWindow(
  79.       'GettingStarted',       // window class name
  80.       'Antialiasing with Text',       // window caption
  81.       WS_OVERLAPPEDWINDOW,    // window style
  82.       Integer(CW_USEDEFAULT), // initial x position
  83.       Integer(CW_USEDEFAULT), // initial y position
  84.       Integer(CW_USEDEFAULT), // initial x size
  85.       Integer(CW_USEDEFAULT), // initial y size
  86.       0,                      // parent window handle
  87.       0,                      // window menu handle
  88.       hInstance,              // program instance handle
  89.       nil);                   // creation parameters
  90.  
  91.    ShowWindow(hWnd, SW_SHOW);
  92.    UpdateWindow(hWnd);
  93.  
  94.    while(GetMessage(msg, 0, 0, 0)) do
  95.    begin
  96.       TranslateMessage(msg);
  97.       DispatchMessage(msg);
  98.    end;
  99. end.
  100.